<template>
  <div class="parent">
    <p class="unitp">单位：tCO2e</p>
    <echartsDom v-if="isShowEcharts" :width="width" :height="height" :option="option" />
    <div v-else>
      <px-empty :image-size="50" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref, watch } from "vue";
import echartsDom from "./echartsDom.vue";
import { accountingEmissionDatatraceability } from "@/api/doubleCarbonManage/dataAnalysis";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  color: {
    type: String,
    default: "#3B82F6"
  },
  chartvalue: {
    type: Object,
    required: true
  }
});
const isShowEcharts = ref(false);
const state = reactive({
  option: {}
});
const { option } = toRefs(state);
const getoptions = () => {
  if (props.chartvalue != null) {
    isShowEcharts.value = true;
    option.value = {
      toolbox: {
        show: true,
        feature: {
          saveAsImage: {
            title: "点击保存为图片",
            name: "碳排放溯源"
          }
        }
      },
      tooltip: {
        trigger: "item",
        triggerOn: "mousemove",
        confine: true
      },

      series: {
        type: "sankey",
        layout: "none",
        levels: [
          {
            depth: 0,
            itemStyle: {
              color: "#fbb4ae"
            },
            lineStyle: {
              color: "source",
              opacity: 0.6
            }
          },
          {
            depth: 1,
            itemStyle: {
              color: "#b3cde3"
            },
            lineStyle: {
              color: "source",
              opacity: 0.6
            }
          },
          {
            depth: 2,
            itemStyle: {
              color: "#ccebc5"
            },
            lineStyle: {
              color: "source",
              opacity: 0.6
            }
          },
          {
            depth: 3,
            itemStyle: {
              color: "#decbe4"
            },
            lineStyle: {
              color: "source",
              opacity: 0.6
            }
          },
          {
            depth: 4,
            itemStyle: {
              color: "#a899aa"
            },
            lineStyle: {
              color: "source",
              opacity: 0.6
            }
          }
        ],
        emphasis: {
          focus: "adjacency"
        },
        layoutIterations: 0,
        labelLayout: {
          moveOverlap: "shiftY"
        },
        data: props.chartvalue.nodes,
        links: props.chartvalue.links
      }
    };
  } else {
    isShowEcharts.value = false;
  }
};
watch(
  () => props.chartvalue,
  newOption => {
    console.log(newOption);
    if (newOption != null) {
      getoptions();
    } else {
      isShowEcharts.value = false;
    }
  }
);
</script>

<style scoped lang="scss">
.parent {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.unitp {
  position: absolute;
}
</style>
